var projectId =  this.getQueryString("projectId")||'88888888888';

$(function(){
	initPowerInstallData(); // 初始化电源装机统计图
	initOutputStatistData(); // 初始化出力统计
	initCarbonData(); // 初始化碳排放统计
	initCostData(); // 初始化发电成本统计
})
function initPowerInstallData(){
	$.ajax({
		url : "../g/service/Sample/getPowerInstallData",
    	type:'post',
        contentType: 'application/json; charset=utf-8',
        data:JSON.stringify({"projectId" : projectId }),
        success : function(data){
			createPowerInstallChart(data);
        }
	})
}
function initOutputStatistData(){
	$.ajax({
		url : "../g/service/Sample/getOutputStatistData",
    	type:'post',
        contentType: 'application/json; charset=utf-8',
        data:JSON.stringify({"projectId" : projectId }),
        success : function(data){
			createOutputStatistChart(data);
        }
	})
}
function initCarbonData(){
	$.ajax({
		url : "../g/service/Sample/getCarbonData",
    	type:'post',
        contentType: 'application/json; charset=utf-8',
        data:JSON.stringify({"projectId" : projectId }),
        success : function(data){
			for(item in data){
				if(item == "系统") {
					$("#sysSumCarbon").html(data[item]);
				} else if(item == "火电") {
					$("#thermalCarbon").html(data[item]);
				} else if(item == "气源") {
					$("#airCarbon").html(data[item]);
				} else if(item == "热源") {
					$("#heatCarbon").html(data[item]);
				}
			}
        }
	})
}
function initCostData(){
	$.ajax({
		url : "../g/service/Sample/getCostData",
    	type:'post',
        contentType: 'application/json; charset=utf-8',
        data:JSON.stringify({"projectId" : projectId }),
        success : function(data){
			for(item in data){
				if(item == "系统") {
					$("#sysSumCost").html(data[item]);
				} else if(item == "火电") {
					$("#thermalCost").html(data[item]);
				} else if(item == "气源") {
					$("#airCost").html(data[item]);
				} else if(item == "热源") {
					$("#heatCost").html(data[item]);
				}
			}
        }
	})
}
function createPowerInstallChart(d) {
	var option = {
		tooltip: {
			trigger: 'item',
			formatter: '{a} <br/>{b}: {c} ({d}%)'
		},
		legend: {
			data: d.legendData
		},
		series: [{
			name: '',
			type: 'pie',
		    selectedMode: 'single',
		    radius: [0, '30%'],
		    label: {
		    	position: 'inner',
		        fontSize: 14
		    },
		    labelLine: {
		        show: false
		    },
		    data: d.inList
		},{
			name: '装机容量（MW）',
		    type: 'pie',
		    radius: ['45%', '60%'],
		    labelLine: {
		        length: 30
		    },
		    label: {
		        formatter: '{a|{a}}{abg|}\n{hr|}\n  {b|{b}：}{c}  {per|{d}%}  ',
		        backgroundColor: '#F6F8FC',
		        borderColor: '#8C8D8E',
		        borderWidth: 1,
		        borderRadius: 4,
		        rich: {
		        	a: {
			            color: '#6E7079',
			            lineHeight: 22,
			            align: 'center'
		        	},
		        	hr: {
			            borderColor: '#8C8D8E',
			            width: '100%',
			            borderWidth: 1,
			            height: 0
		        	},
		        	b: {
			            color: '#4C5058',
			            fontSize: 14,
			            fontWeight: 'bold',
			            lineHeight: 33
		        	},
		        	per: {
			            color: '#fff',
			            backgroundColor: '#4C5058',
			            padding: [3, 4],
			            borderRadius: 4
		        	}
		        }
		    },
		    data: d.outList
		}]
	};

	var chartDom = document.getElementById('powerInstallChart');
	var myChart = echarts.init(chartDom);
	option && myChart.setOption(option);
	window.addEventListener("resize", () => {
		if(myChart){
			myChart.resize()
		}
	});
}

function createOutputStatistChart(data){
	var database=[];
	for(item in data){
		var data1={"value":data[item],"name":item}
		database.push(data1);
	}
	 
	var chartDom = document.getElementById('outputStatistChart');
	var myChart = echarts.init(chartDom);
	var option = {
			tooltip: {
				trigger: 'item'
			},
			legend: {
				left: 'center'
			},
			series: [
				{
					name: '累计出力',
					type: 'pie',
				    radius: ['50%', '80%'],
				    avoidLabelOverlap: false,
				    itemStyle: {
				    	borderRadius: 10,
				        borderColor: '#fff',
				        borderWidth: 2
				    },
				    label: {
				        show: false,
				        position: 'center'
				    },
				    emphasis: {
				    	label: {
				        	show: true,
				        	fontSize: 40,
				        	fontWeight: 'bold'
				        }
				    },
				    labelLine: {
				        show: false
				    },
				    data: database
				}
			]
		};

	option && myChart.setOption(option);
	window.addEventListener("resize", () => {
		if(myChart){
			myChart.resize()
		}
	})
}

function getQueryString (name){
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	return r ? unescape(r[2]) : null;
}